const tr = JSON.parse(
    '{"1":13,"2":12,"3":46,"4":31,"5":43,"6":18,"7":40,"8":28,"9":5,"f":0,"Z":1,"o":2,"d":3,"R":4,"X":6,"Q":7,"D":8,"S":9,"U":10,"m":11,"y":14,"C":15,"k":16,"r":17,"z":19,"B":20,"q":21,"i":22,"v":23,"e":24,"Y":25,"a":26,"h":27,"b":29,"t":30,"x":32,"s":33,"W":34,"p":35,"H":36,"n":37,"J":38,"E":39,"j":41,"L":42,"V":44,"G":45,"g":47,"u":48,"M":49,"T":50,"K":51,"N":52,"P":53,"A":54,"w":55,"c":56,"F":57}'
);

const s = [11, 10, 3, 8, 4, 6];
const xor = 177451812,
    add = 8728348608;

function BVtoAV(BV, force = false) {
    if (!force || (window.__INITIAL_STATE__ && window.__INITIAL_STATE__.aid)) {
        return window.__INITIAL_STATE__.aid; // 这个鬼东西里面藏着很多视频地信息
    } else {
        let r = 0;
        for (let i = 0; i < 6; i++) {
            r += tr[BV[s[i]]] * Math.pow(58, i);
        }
        return (r - add) ^ xor;
    }
}

export { BVtoAV };
